/*
 * @(#)MaintDmsArchiveAction.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.dms.web;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.quartz.SchedulerException;

import com.dcivision.dms.DmsErrorConstant;
import com.dcivision.dms.bean.DmsArchive;
import com.dcivision.dms.bean.DmsDocument;
import com.dcivision.dms.bean.DmsRoot;
import com.dcivision.dms.bean.DmsValidation;
import com.dcivision.dms.core.DmsArchiveManager;
import com.dcivision.dms.core.DocumentOperationManager;
import com.dcivision.dms.core.DocumentRetrievalManager;
import com.dcivision.dms.core.RootRetrievalManager;
import com.dcivision.dms.dao.DmsArchiveDAObject;
import com.dcivision.dms.dao.DmsArchiveDetailDAObject;
import com.dcivision.dms.dao.DmsDocumentDAObject;
import com.dcivision.dms.dao.DmsRootDAObject;
import com.dcivision.framework.ApplicationContainer;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.Utility;
import com.dcivision.framework.web.AbstractActionForm;
import com.dcivision.framework.web.AbstractMaintAction;

/**
  MaintDmsArchiveAction.java
  This class is for Dms archive.
    @author          Zoe Shum
    @company         DCIVision Limited
    @creation date   23/10/2003
    @version         $Revision: 1.62.2.2 $
 */
/* ********************************Modify History***********************************************
 * Modify by  : Jicle.Wang 
 * Modify date: 2006/08/22
 * BugID      : 6153
 * Description: Show the same message as clicking 'SAVE' when click 'MORE' in new Archive.
 * *********************************************************************************************
 */
public class MaintDmsArchiveAction extends AbstractMaintAction {

  public static final String REVISION = "$Revision: 1.62.2.2 $";
  protected final static String DMS_MESSAGE_RECORD_INSTERT_TIME="dms.message.record_insert_time";

  public MaintDmsArchiveAction() {
    super();
  }

  /**
   * getMajorDAOClassName
   *
   * @return  The class name of the major DAObject will be used in this action.
   */
  
  public String getMajorDAOClassName() {
    return ("com.dcivision.dms.dao.DmsArchiveDAObject");
  }

  /**
   * getFunctionCode
   *
   * @return  The corresponding system function code of action.
   */
  
  public String getFunctionCode() {
    return (SystemFunctionConstant.DMS_ARCHIVE);
  }
  
  /**
   *  Method execute() - generaic function of result list handling               
   *
   *  @param      mapping               ActionMapping from struts
   *  @param      form                  ActionForm from struts
   *  @param      request               HttpServletReuqest
   *  @param      respond               HttpServletRespond
   *  @return     ActionForward         Return the action forward object for struts
   *  @throws     ServletException      Throws ServletException
   */
  
  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException {
  	List folderList = this.getFolder(new ArrayList(),new Integer(129),new Integer(40),request);
  	log.debug("**********" + folderList.size());
  	
    SessionContainer sessionContainer = this.getSessionContainer(request);
    Connection conn = this.getConnection(request);
    HttpSession session = request.getSession();
    ActionForward retValue;
    DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);
    DmsDocument documentRoot = null;
    MaintDmsArchiveForm maintForm = (MaintDmsArchiveForm) form;

    String opMode = maintForm.getOpMode();
    String navMode = (maintForm!=null) ? maintForm.getNavMode() : request.getParameter("navMode");
    //if (Utility.isEmpty(opMode) || GlobalConstant.NAV_MODE_NEW.equals(opMode) ) {
    //ActionForward forward = this.retrieveFunctionCode(request, response, mapping);  if (forward!=null) {return forward;}
    ActionForward forward = this.retrieveFunctionCode(request, response, mapping);
    if (forward!=null) {
      return forward;
    }
    
    try {
      DmsDocumentDAObject dmsDocumentDAO = new DmsDocumentDAObject(sessionContainer,conn);
      DmsDocument dmsDocument = null;
      
      //add by lee lv begin...................
      if (GlobalConstant.OP_MODE_LIST_RETAIN.equals(opMode)) {
        //To filter the archive ids make them not contains each other(each id is not other's parentId).
        Set distinctID = new HashSet();
        
        String[] archiveFolder = (String[])session.getAttribute("archiveFolder");
        if (!Utility.isEmpty(archiveFolder)) {
          for (int i=0; i<archiveFolder.length; i++) {
            distinctID.add(new Integer(archiveFolder[i]));
          }
        }
        
        String addArchiveID = maintForm.getAddArchiveID();
        if (!Utility.isEmpty(addArchiveID)) {
          String[] newArchiveFolder = addArchiveID.split(";");
          if (!Utility.isEmpty(newArchiveFolder)) {
            for (int i=0; i<newArchiveFolder.length; i++) {
              distinctID.add(new Integer(newArchiveFolder[i]));
            }
          }
        }
        
        List tmpArchiveFloder = new ArrayList();
        if (!Utility.isEmpty(distinctID)) {
          Iterator iterator = distinctID.iterator();
          while (iterator.hasNext()) {
            Integer docID = (Integer)iterator.next();
            DmsDocument doc = docRetrievalManager.getDocumentByID(docID);
            List parentIdList = docRetrievalManager.getParentDocumentList(docID);
            parentIdList.add(docRetrievalManager.getRootFolderByRootID(doc.getRootID()).getID());
            parentIdList.remove(docID);
            boolean found = false;
            if (!Utility.isEmpty(parentIdList)) {
              for (int i=0; i<parentIdList.size(); i++) {
                Integer pid = (Integer)parentIdList.get(i);
                if (distinctID.contains(pid)) {
                  found = true;
                  break;
                }
              }
            }
            if (!found) {
              tmpArchiveFloder.add(docID);
            }
          }
          
          String[] newArchiveFolder = new String[tmpArchiveFloder.size()];
          for (int i=0; i<tmpArchiveFloder.size(); i++) {
            newArchiveFolder[i] = String.valueOf(tmpArchiveFloder.get(i));
          }
          request.getSession().setAttribute("archiveFolder", newArchiveFolder);
        }
      }else if (GlobalConstant.OP_MODE_LIST_DELETE.equals(opMode)) {
        //remove id from archiveFolder session
        String[] basicSelectID = maintForm.getBasicSelectedID();
        String[] archiveFolder = (String[])request.getSession().getAttribute("archiveFolder");
        List lArchiveFolder = new ArrayList();
        for (int i=0; i<archiveFolder.length; i++) {
          lArchiveFolder.add(archiveFolder[i]);
        }
        for (int i = 0; i < basicSelectID.length; i++){
          if (lArchiveFolder.contains(basicSelectID[i])) {
            lArchiveFolder.remove(basicSelectID[i]);
          }
        }
        String[] newArchiveFolder = new String[lArchiveFolder.size()];
        for (int i=0; i<lArchiveFolder.size(); i++) {
          newArchiveFolder[i] = (String)lArchiveFolder.get(i);
        }
        request.getSession().setAttribute("archiveFolder", newArchiveFolder);
      }
      //add by lee lv end...........................
      
    	//Archive folder
      List archiveFolderList = new ArrayList();
      String[] archiveFolder = (String[])request.getSession().getAttribute("archiveFolder");
      
      if (!Utility.isEmpty(archiveFolder)){
      	for (int i =0; i < archiveFolder.length; i++){
        	dmsDocument = (DmsDocument)dmsDocumentDAO.getObjectByID(TextUtility.parseIntegerObj(archiveFolder[i]));
        	archiveFolderList.add(dmsDocument);
        }
      }
      request.setAttribute("archiveFolderList",archiveFolderList);
      
      // Retieve the root folder document object.
      documentRoot = docRetrievalManager.getRootFolderByRootID(TextUtility.parseIntegerObj(maintForm.getRootID()));
      request.setAttribute("rootFolder", documentRoot);

      // Retrieve the folder list for folder tree listing.
      //List folderTreeList = docRetrievalManager.getFolderByParentIDRootID(documentRoot.getID(), new Integer(maintForm.getRootID()));
      //request.setAttribute("folderTreeList", folderTreeList);

      // Retrieve the location path of the folder.
      Integer parentID = new Integer(maintForm.getParentID());
      String path = docRetrievalManager.getLocationPath(parentID);
      request.setAttribute("location", path);

      // Retrieve the accessible public root list.
      DmsRootDAObject dmsRootDAO = new DmsRootDAObject(sessionContainer, conn);
      List publicRootList = dmsRootDAO.getPublicRootList();
      request.setAttribute("publicRootList", publicRootList);

      sessionContainer = null;
      docRetrievalManager.release();
//      dmsRootDAO = null;      
    } catch (ApplicationException appEx) {
      this.rollback(request);
      handleApplicationException(request, appEx);
    } finally {
      conn = null;
    }

    if (isError(request)) {
      maintForm.setNavMode(GlobalConstant.NAV_MODE_NEW);
      return mapping.findForward(GlobalConstant.NAV_MODE_NEW);
    }
    //}
    if (GlobalConstant.OP_MODE_LIST_RETAIN.equals(opMode) || GlobalConstant.OP_MODE_LIST_DELETE.equals(opMode)) {
      maintForm.setOpMode("");
      maintForm.setNavMode(GlobalConstant.NAV_MODE_NEW);
      return mapping.findForward(GlobalConstant.NAV_MODE_NEW);
    }
    if (GlobalConstant.OP_MODE_INSERT.equals(opMode)) {
      // Insert operation.
      try {
        this.insertRecord2(mapping, maintForm, request, response);
        this.handleWorkflowRoutine(mapping, maintForm, request, response, opMode, navMode);
        this.commit(request);
        if("Y".equals(maintForm.getArchiveNow())){
          String[] messageStr=(String[])request.getAttribute("messageStr");
          if(!Utility.isEmpty(messageStr)){
            addMessage(request,DmsErrorConstant.DMS_MESSAGE_RECORD_INSTERTED,messageStr[0]);
            for(int i=1;i<messageStr.length;i++){
              addError(request,DmsErrorConstant.NO_CAPACTIY_TO_RESTORE_DOCUMENT,messageStr[i]);
            }
          }
        }else{
          //addMessage(request, DMS_MESSAGE_RECORD_INSTERT_TIME,maintForm.getDatetime());
        }
      } catch (ApplicationException appEx) {
        this.rollback(request);
        handleApplicationException(request, appEx);
      }
      if (isError(request)) {
        maintForm.setNavMode(GlobalConstant.NAV_MODE_NEW);
        return mapping.findForward(GlobalConstant.NAV_MODE_NEW);
      } else {
        maintForm.setNavMode(GlobalConstant.NAV_MODE_VIEW);
        return mapping.findForward(GlobalConstant.NAV_MODE_VIEW);
      }
      /* Jicle.Wang 6153 2006/08/22 Start */
    }else if (GlobalConstant.OP_MODE_INSERT_NEW.equals(opMode)) {
        try {
          this.insertRecord2(mapping, maintForm, request, response);
          this.handleWorkflowRoutine(mapping, maintForm, request, response, opMode, navMode);
          this.commit(request);
          form.reset(mapping, request);
          this.init(mapping, maintForm, request, response);
          if("Y".equals(maintForm.getArchiveNow())){
              String[] messageStr=(String[])request.getAttribute("messageStr");
              if(!Utility.isEmpty(messageStr)){
                addMessage(request,DmsErrorConstant.DMS_MESSAGE_RECORD_INSTERTED,messageStr[0]);
                for(int i=1;i<messageStr.length;i++){
                  addError(request,DmsErrorConstant.NO_CAPACTIY_TO_RESTORE_DOCUMENT,messageStr[i]);
                }
              }
            }else{
              addMessage(request, DMS_MESSAGE_RECORD_INSTERT_TIME,maintForm.getDatetime());
            }
        } catch (ApplicationException appEx) {
          this.rollback(request);
          handleApplicationException(request, appEx);
        }
        if (isError(request)) {
          maintForm.setNavMode(GlobalConstant.NAV_MODE_NEW);
          return mapping.findForward(GlobalConstant.NAV_MODE_NEW);
        } else {
          maintForm.setNavMode(GlobalConstant.NAV_MODE_NEW);
          return mapping.findForward(GlobalConstant.NAV_MODE_NEW);
        }
        /* Jicle.Wang 6153 2006/08/22 End   */    
      } else{
      retValue = super.execute(mapping, form, request, response);
      return retValue;
    }
  }
  
  public void insertRecord2(ActionMapping mapping, AbstractActionForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
    MaintDmsArchiveForm archiveForm = (MaintDmsArchiveForm) form;
    
    // trim archive name escape space char (lee 06/11/27 EIP-1075)
    String archiveName = archiveForm.getArchiveName();
    if (archiveName!=null) {
      archiveForm.setArchiveName(archiveName.trim());
    }
    
    SessionContainer sessionContainer = this.getSessionContainer(request);
    Connection conn = this.getConnection(request);
    DmsArchiveManager archiveManager = new DmsArchiveManager(sessionContainer, conn);
    
    DmsValidation validation = archiveManager.validateArchiveAction(form, request);
    if (!validation.isSuccess()) {
      if (validation.isInvalidName()) {
        String sysInvalidCharacters = SystemParameterFactory.getSystemParameter(SystemParameterConstant.INVALID_CHARACTER);
        addError(request, "errors.framework.character_error", sysInvalidCharacters);
      }else if (validation.isDuplicateName()) {
        addError(request, DmsErrorConstant.DUPLICATE_ARCHIVE_NAME);
      }else if (validation.isPersonalRoot()) {
        addError(request, DmsErrorConstant.CANNOT_ARCHIVE_PERSONAL_FOLDER);
      }else if (validation.isNotEnoughDiskSpace()) {
        addError(request, "errors.dms.not_enough_disk_space", String.valueOf(validation.getDiskSpaceFree()), String.valueOf(validation.getDiskSpaceRequire()));
      }else {
        if (validation.getLstIdAccept().isEmpty()) {
          addError(request, DmsErrorConstant.NO_DOCUMENT_TO_ARCHIVE);
        }
      }
    }else {
      if(!"Y".equals(archiveForm.getArchiveNow())){
        this.setToScheduler(form,request);
        addMessage(request, DMS_MESSAGE_RECORD_INSTERT_TIME, archiveForm.getDatetime());
      }else {
        ApplicationContainer container = (ApplicationContainer)request.getSession().getServletContext().getAttribute(GlobalConstant.APPLICATION_CONTAINER_KEY);
        String cacheKey = "A"+sessionContainer.getSessionID()+""+System.currentTimeMillis();
        try {
          //2.2.1: check and lock operation id to application cache
          boolean success = true;
          for (int i=0; i<validation.getLstIdAccept().size(); i++) {
            List listIdAccept = (List)validation.getLstIdAccept().get(i);
            success = container.checkAndLockDocumentOperationID(cacheKey, listIdAccept, "ACDIMU");
            if (success==false) { break; }
          }
          if (!success) {
            this.addError(request, "errors.dms.fail_to_archive", "");
            this.addError(request, "errors.dms.cannot_edit_now");
          }else {
            //2.2.2: begin archive documents
            archiveManager.archiveDocument(form, request, validation);
            int counter = 0;
            for (int i=0; i<validation.getLstIdAccept().size(); i++) {
              counter += ((List)validation.getLstIdAccept().get(i)).size();
            }
            addMessage(request, DmsErrorConstant.DMS_MESSAGE_RECORD_INSTERTED,""+counter);
          }
        }catch (ApplicationException ex) {
          throw ex;
        }catch (Exception ex) {
          throw new ApplicationException(ex);
        }finally {
          container.unlockDmsDocumentOperationID(cacheKey);
          container = null;
        }
      }
    }
  }
  
  /**
   *  Method insertRecord() - generaic function of result insert handling               
   *
   *  @param      mapping               ActionMapping from struts
   *  @param      form                  ActionForm from struts
   *  @param      request               HttpServletReuqest
   *  @param      respond               HttpServletRespond
   *  @return     ActionForward         Return the action forward object for struts
   *  @throws     ServletException      Throws ServletException
   *  @deprecated This method is deprecated.
   */
  
  
  public void insertRecord(ActionMapping mapping, AbstractActionForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
    SessionContainer sessionContainer = this.getSessionContainer(request);
    Connection conn = this.getConnection(request);
    DmsArchiveDAObject archiveDAO = new DmsArchiveDAObject(sessionContainer, conn);
    DmsArchiveDetailDAObject archiveDetailDAO = new DmsArchiveDetailDAObject(sessionContainer, conn);
    DmsDocumentDAObject documentDAO = new DmsDocumentDAObject(sessionContainer, conn);
    DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);
    DocumentOperationManager docOperationManager = new DocumentOperationManager(sessionContainer, conn);
    RootRetrievalManager rootRetrievalManager = new RootRetrievalManager(sessionContainer, conn);
    MaintDmsArchiveForm maintForm=(MaintDmsArchiveForm)form;
    boolean genExcel=SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.DMS_ENABLE_ARCHIVE_EXCEL);
    
    DmsRoot dmsRoot=rootRetrievalManager.getRootObject(TextUtility.parseIntegerObj(maintForm.getRootID()));
    if(DmsRoot.PERSONAL_ROOT.equals(dmsRoot.getRootType())){
      throw new ApplicationException(DmsErrorConstant.CANNOT_ARCHIVE_PERSONAL_FOLDER);
    }
    //  check for invalid characters on archive name only
    TextUtility.stringValidation(maintForm.getArchiveName());
    
    //check doubled archive name .
    List archiveNameList=archiveDAO.getListByArchiveName(maintForm.getArchiveName());
    
    if(archiveNameList.size()>0){
      throw new ApplicationException(DmsErrorConstant.DUPLICATE_ARCHIVE_NAME);
    }
    
    MaintDmsArchiveForm archiveForm = (MaintDmsArchiveForm) form;
    String archiveName = archiveForm.getArchiveName();
    String[] userDefinedIndex = archiveForm.getUserDefinedFieldID();
    Integer destinationID = TextUtility.parseIntegerObj(archiveForm.getDestinationID());
    Integer parentID = TextUtility.parseIntegerObj(archiveForm.getParentID());
    Integer rootID = TextUtility.parseIntegerObj(archiveForm.getRootID());
    
    if("Y".equals(maintForm.getArchiveNow())){
      DmsArchiveManager dmsArchiveManager=new DmsArchiveManager(sessionContainer,conn);
      
//      List dmsArchiveList= dmsArchiveManager.getAllArchiveDocList(destinationID,rootID,maintForm.getArchiveDateFrom(),maintForm.getArchiveDateTo(),userDefinedIndex,sessionContainer.getUserRecordID());
      List dmsArchiveList = new ArrayList();
      String[] basicSelectID = (String[])request.getSession().getAttribute("archiveFolder");//maintForm.getBasicSelectedID();
      DmsDocumentDAObject dmsDocumentDAObject = new DmsDocumentDAObject(sessionContainer,conn);
      List tmpList = null;
      for (int i = 0; i < basicSelectID.length; i++){
      	DmsDocument dmsDocument = (DmsDocument)dmsDocumentDAObject.getObjectByID(TextUtility.parseIntegerObj(basicSelectID[i]));
      	tmpList = dmsArchiveManager.getAllArchiveDocList(documentDAO, new Integer[]{dmsDocument.getID()},dmsDocument.getRootID(),maintForm.getArchiveDateFrom(),maintForm.getArchiveDateTo(),userDefinedIndex,sessionContainer.getUserRecordID());
      	if (tmpList == null) {
          continue;
        }
      	dmsArchiveList.addAll(tmpList);
      }
      
      ArrayList clipboardList = (ArrayList)request.getSession().getAttribute("DMS_CLIPBOARD");
      List defaultProfileSettingList = (List) request.getSession().getServletContext().getAttribute("DMS_DEF_PROFILE");
      String offlineViewPath=request.getSession().getServletContext().getRealPath("viewer");
      DmsArchive dmsArchive=(DmsArchive)maintForm.getFormData();
      dmsArchive.setRecordStatus(GlobalConstant.RECORD_STATUS_ACTIVE);
      String[] messageStr=dmsArchiveManager.startArchive(dmsArchiveList,dmsArchive,clipboardList,defaultProfileSettingList,offlineViewPath,userDefinedIndex,maintForm.getArchiveNow());
      request.setAttribute("messageStr",messageStr);
    }else{
      //force to Scheduler
      this.setToScheduler(form,request);
    } 
    //this.commit(conn);
    //dmsArchive.setRootID(rootID);
    //archiveForm.setFormData(dmsArchive);
    
    try {} catch (Exception e) {
      log.error(e, e);
    } finally {    
      documentDAO = null;
      archiveDetailDAO = null;
      sessionContainer = null;
      archiveDAO = null;
      docOperationManager.release();
      docRetrievalManager.release();
      rootRetrievalManager.release();
      conn = null;
    }

  }
  
  /**
   * for scheduler archvie documents.
   * @param form
   * @param request
   */
  private void setToScheduler(AbstractActionForm form,HttpServletRequest request) {
    SessionContainer sessionContainer=this.getSessionContainer(request);  
    MaintDmsArchiveForm archiveForm = (MaintDmsArchiveForm) form;
    String DestinationID = "";
    
    // archive id must load from the session attribute. (lee 06/10/26 EIP-603)
    String[] basicSelectID = (String[])request.getSession().getAttribute("archiveFolder");
    //String[] basicSelectID = archiveForm.getBasicSelectedID();
    
    for(int i=0;i<basicSelectID.length;i++){
    	if (i != basicSelectID.length -1){
    		DestinationID = DestinationID + basicSelectID[i] + ",";
    	}else {
    		DestinationID = DestinationID + basicSelectID[i];
    	}
    }
    try{
      ArrayList clipboardList = (ArrayList)request.getSession().getAttribute("DMS_CLIPBOARD");
      List defaultProfileSettingList = (List) request.getSession().getServletContext().getAttribute("DMS_DEF_PROFILE");
      String offlineViewPath=request.getSession().getServletContext().getRealPath("viewer");
      java.util.Date triggerTime = null;
      org.quartz.SimpleTrigger trigger = null;

      triggerTime =archiveForm.getDatetime();
      List userDefinedFieldIDList=new ArrayList();
      if(!Utility.isEmpty(archiveForm.getUserDefinedFieldID())){
        for(int i=0;i<archiveForm.getUserDefinedFieldID().length;i++){
          userDefinedFieldIDList.add(archiveForm.getUserDefinedFieldID()[i]);
        }
      }
      
      org.quartz.Scheduler sched = com.dcivision.framework.SchedulerFactory.getScheduler(); 
      
      org.quartz.JobDataMap dataMap = new org.quartz.JobDataMap();
      dataMap.put("archiveName", archiveForm.getArchiveName());
      dataMap.put("archiveType",archiveForm.getArchiveType());
      dataMap.put("destinationID",DestinationID);
      dataMap.put("rootID",archiveForm.getRootID());
      dataMap.put("userDefinedFieldIDList",userDefinedFieldIDList);
      dataMap.put("startDate",archiveForm.getArchiveDateFrom());
      dataMap.put("endDate",archiveForm.getArchiveDateTo());
      dataMap.put("clipboardList",clipboardList);
      dataMap.put("defaultProfileSettingList",defaultProfileSettingList);
      dataMap.put("offlineViewPath",offlineViewPath);
      dataMap.put("userRecordID",TextUtility.formatIntegerObj(sessionContainer.getUserRecordID()));
      dataMap.put("userRecord", sessionContainer.getUserRecord());
      dataMap.put("userIPAddress", sessionContainer.getUserIPAddress());
      
      // lee 06/12/06 EIP-965 / update job name and group
      /*
      org.quartz.JobDetail job = new org.quartz.JobDetail(
          "checkout expiry time " + new java.util.Date(),
          "CHECKOUT_JOBGROUP"+Math.random(),
          com.dcivision.dms.core.DmsArchiveSchedulerJob.class);
      job.setJobDataMap(dataMap);
      trigger = new org.quartz.SimpleTrigger("CheckInExpirt","CHECKIN_GROUP"+Math.random(),triggerTime, null,0,0);
      */
      String jobName = GlobalConstant.JOB_PREFIX_DMS_ARCHIVE+archiveForm.getArchiveName()+"_"+System.currentTimeMillis();
      String jobGroup = GlobalConstant.JOB_PREFIX_DMS_ARCHIVE+"GROUP";
      org.quartz.JobDetail job = new org.quartz.JobDetail(jobName, jobGroup, com.dcivision.dms.core.DmsArchiveSchedulerJob.class);
      job.setJobDataMap(dataMap);
      trigger = new org.quartz.SimpleTrigger(jobName,jobGroup,triggerTime, null,0,0);
      // lee 06/12/06 EIP-965 end
      
      trigger.setMisfireInstruction(org.quartz.SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
      //logger.info("******** Trigger created");
      //logger.info(job.getFullName() + " will run at: " + trigger.getNextFireTime() + " & repeat: " + trigger.getRepeatCount() + "/" + trigger.getRepeatInterval());
      
      java.util.Date ft = sched.scheduleJob(job, trigger);
      sched = null;
    }catch(SchedulerException e){
    }
  }
  
  public List getFolder(List folderList,Integer parenetID, Integer rootID,HttpServletRequest request) throws ServletException {
  	List tmpFolderList = new ArrayList();
  	
  	List subFolderList = new ArrayList();
  	SessionContainer sessionContainer = this.getSessionContainer(request);
  	Connection conn = this.getConnection(request);
  	DmsDocumentDAObject dmsDocumentDAO = new DmsDocumentDAObject(sessionContainer,conn);
  	tmpFolderList = dmsDocumentDAO.getFolderListByParentID(parenetID,rootID,"Z",false);
  	if (!Utility.isEmpty(tmpFolderList)){
  		for (int i = 0; i < tmpFolderList.size(); i++){
  			DmsDocument folder = (DmsDocument)tmpFolderList.get(i);
  			subFolderList = this.getFolder(folderList,folder.getID(),folder.getRootID(),request);
  			if (!Utility.isEmpty(subFolderList)){
  				for (int k = 0; k < folderList.size(); k++){
  					folderList.add(subFolderList.get(k));
  				}
  			}
  		}
  	}
  	return folderList;
  }
  
}